package com.zjut.multithreading.controller;

import com.zjut.multithreading.tool.SpringBootBeanAutowiringSupport;
import com.zjut.multithreading.service.TimerTaskService;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;


@Component
public class PingJob implements Job {

    @Autowired
    TimerTaskService timerTaskService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap dataMap = jobExecutionContext.getJobDetail().getJobDataMap();
//        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);    //在springboot框架中不生效
        SpringBootBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        Date CurrentDate =new Date();
        SimpleDateFormat dateFormatDay = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormatTime = new SimpleDateFormat("HH:mm:ss");
        String date = dateFormatDay.format(CurrentDate);
        String time = dateFormatTime.format(CurrentDate);
        timerTaskService.doPing(date, time, String.valueOf(CurrentDate.getHours()));
    }
}
